package com.acmen.easyapi.model;

import com.alibaba.fastjson.annotation.JSONField;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @author acmen
 * 参数节点
 */
public class ParamNode {
    /**
     * 节点名
     */
    protected String name;
    /**
     * 中文描述
     */
    protected String label;

    /**
     * 节点类型名称
     */
    protected String type;

    /**
     * 节点类型
     */
    protected String typeAlias;
    /**
     * 样例
     */
    protected Object example;

    /**
     * 样例
     */
    protected Object example2;
    /**
     * 参数说明
     */
    protected List<String> notes;

    /**
     * 是否为数组
     */
    protected boolean array;

    /**
     * 是否弃用
     */
    protected boolean deprecated = false;

    protected String dictType;

    /**
     * 字典说明
     */
    protected List<Dictionary> dictionaries;

    @JSONField(serialize = false,deserialize = false)
    public List<ParamNode> getSubNodeList() {
        try{
            Field field = this.getClass().getDeclaredField("subNodes");
            field.setAccessible(true);
            return (List)field.get(this);
        }catch (Exception e){
            return new ArrayList<>();
        }
    }

    public String getName() {
        return name;
    }

    public ParamNode setName(String name) {
        this.name = name;
        return this;
    }

    public String getTypeAlias() {
        return typeAlias;
    }

    public ParamNode setTypeAlias(String typeAlias) {
        this.typeAlias = typeAlias;
        return this;
    }

    public Object getExample() {
        return example;
    }

    public ParamNode setExample(Object example) {
        this.example = example;
        return this;
    }
    public List<String> getNotes() {
        return notes;
    }
    public ParamNode addNote(String note) {
        if(notes==null){
            notes = new ArrayList<>();
        }
        notes.add(note);
        return this;
    }
    public ParamNode setNotes(List<String> notes) {
        this.notes = notes;
        return this;
    }

    public String getLabel() {
        return label;
    }

    public ParamNode setLabel(String label) {
        this.label = label;
        return this;
    }

    public boolean isDeprecated() {
        return deprecated;
    }

    public ParamNode setDeprecated(boolean deprecated) {
        this.deprecated = deprecated;
        return this;
    }
    public List<Dictionary> getDictionaries() {
        return dictionaries;
    }
    public ParamNode setDictionaries(List<Dictionary> dictionaries) {
        this.dictionaries = dictionaries;
        return this;
    }

    public boolean isArray() {
        return array;
    }

    public ParamNode setArray(boolean array) {
        this.array = array;
        return this;
    }

    public String getType() {
        return type;
    }

    public ParamNode setType(String type) {
        this.type = type;
        return this;
    }

    public Object getExample2() {
        return example2;
    }

    public ParamNode setExample2(Object example2) {
        this.example2 = example2;
        return this;
    }

    public String getDictType() {
        return dictType;
    }

    public ParamNode setDictType(String dictType) {
        this.dictType = dictType;
        return this;
    }
}
